home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
- /* $Id: COMFlat.cpp 1.9 1997/06/20 22:30:12 damien Exp $ */
-
- ////////////////////////////////////////////////////////////////////////
- // Geometric Primitive Example : Flat surface //
- //--------------------------------------------------------------------//
- // Implementation of the Flat Interface //
- ////////////////////////////////////////////////////////////////////////
-
- #ifndef __COMFLAT__
- #include "COMFlat.h"
- #endif
-
- #ifndef __3DCOFAIL__
- #include "3DCoFail.h"
- #endif
-
- #ifndef __ISHFMESH__
- #include "IShFMesh.h"
- #endif
-
- #ifndef __I3DSHUTI__
- #include "I3DShUti.h"
- #endif
-
- // Constructor / Destructor of the C++ Object :
- Flat::Flat() {
- fCRef=0; // Reference Counter
- }
-
- Flat::~Flat() {
- global_count_Obj--;
- }
-
- // IUnknown Interface :
- HRESULT Flat::QueryInterface(THIS_ REFIID riid,LPVOID FAR* ppvObj) {
- *ppvObj=NULL;
-
- // The Flat knows the interfaces of the parent Objects
- if (IsEqualIID(riid, IID_IUnknown))
- *ppvObj=(IUnknown*)(I3DExGeometricPrimitive*)this;
- else if (IsEqualIID(riid, IID_I3DExGeometricPrimitive))
- *ppvObj=(I3DExGeometricPrimitive*)this;
- else if (IsEqualIID(riid, IID_I3DExDataExchanger))
- *ppvObj=(I3DExDataExchanger*)this;
- else if (IsEqualIID(riid, IID_I3DExtension))
- *ppvObj=(I3DExtension*)this;
-
- // we must add reference if we return an interface
- if (*ppvObj!=NULL) {
- ((LPUNKNOWN)*ppvObj)->AddRef();
- return NOERROR;
- }
- else {
- return ResultFromScode(E_NOINTERFACE);
- }
- }
-
- ULONG Flat::AddRef(THIS) {
- return fCRef++;
- }
-
- ULONG Flat::Release(THIS) {
- ULONG UnreleaseObject=fCRef--;
-
- if (fCRef==0)
- delete this; // No reference left, so destroy the object
-
- return UnreleaseObject;
- // local variable used, because fCRef can be destroyed before.
- }
-
- // I3DExtension methods :
- I3DExtension* Flat::Clone(THIS) {
- Flat* theClone = new Flat;
- if (theClone) {
- theClone->AddRef();
- }
- return (I3DExtension*)theClone;
- }
-
- HRESULT Flat::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
- InitCoFailure(shellUtilities);
- return NOERROR;
- }
-
- // I3DExDataExchanger methods :
- ExtensionDataMap* Flat::GetExtensionDataMap(THIS) {
- return NULL;
- }
-
- void* Flat::GetExtensionDataBuffer(THIS) {
- return NULL;
- }
-
- HRESULT Flat::ExtensionDataChanged(THIS) {
- return NOERROR;
- }
-
- HRESULT Flat::HandleEvent(THIS_ ULONG SourceID) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- short Flat::GetResID(THIS) {
- return -1; // always return -1, if you do not have a view
- }
-
- // I3DExGeometricPrimitive methods
- // -- Geometry calls
- HRESULT Flat::EnumPatches(THIS_ EnumPatchesCallback callback, void* privData) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Flat::EnumFacets(THIS_ EnumFacetsCallback callback, void* privData, NUM3D fidelity) {
- FACET3D Facet;
- NUM3D size = 10.0;
- VECTOR3D normal;
-
- normal[0]=0.0;
- normal[1]=0.0;
- normal[2]=1.0;
-
- Facet.fUVSpace=0;
- Facet.fVertices[0].fVertex[0]=-size;
- Facet.fVertices[0].fVertex[1]=-size;
- Facet.fVertices[0].fVertex[2]=0.0;
- Facet.fVertices[0].fUV[0]=0.0;
- Facet.fVertices[0].fUV[1]=0.0;
- Facet.fVertices[0].fNormal[0]=normal[0];
- Facet.fVertices[0].fNormal[1]=normal[1];
- Facet.fVertices[0].fNormal[2]=normal[2];
-
- // Common points of the 2 facets
- Facet.fVertices[1].fVertex[0]=size;
- Facet.fVertices[1].fVertex[1]=-size;
- Facet.fVertices[1].fVertex[2]=0.0;
- Facet.fVertices[1].fUV[0]=size*2.0;
- Facet.fVertices[1].fUV[1]=0.0;
- Facet.fVertices[1].fNormal[0]=normal[0];
- Facet.fVertices[1].fNormal[1]=normal[1];
- Facet.fVertices[1].fNormal[2]=normal[2];
-
- Facet.fVertices[2].fVertex[0]=-size;
- Facet.fVertices[2].fVertex[1]=size;
- Facet.fVertices[2].fVertex[2]=0.0;
- Facet.fVertices[2].fUV[0]=0.0;
- Facet.fVertices[2].fUV[1]=size*2.0;
- Facet.fVertices[2].fNormal[0]=normal[0];
- Facet.fVertices[2].fNormal[1]=normal[1];
- Facet.fVertices[2].fNormal[2]=normal[2];
-
- // First Facet
- callback(&Facet,privData);
-
- Facet.fVertices[0].fVertex[0]=size;
- Facet.fVertices[0].fVertex[1]=size;
- Facet.fVertices[0].fVertex[2]=0.0;
- Facet.fVertices[0].fUV[0]=size*2.0;
- Facet.fVertices[0].fUV[1]=size*2.0;
-
- // Second Facet
- callback(&Facet,privData);
-
- return NOERROR;
- }
-
- void AccuFacet(FACET3D* facet, void* accu) {
- ((IShFacetMeshAccumulator*)accu)->AddFacet(facet);
- }
-
- HRESULT Flat::GetNbrLOD(short &nbrLod) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Flat::GetLOD(short lodIndex, NUM3D &lod) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Flat::MakeFacetMesh(short index, FacetMesh &amesh) {
- IShFacetMeshAccumulator* accu;
- gShellUtilities->CoCreateInstance(CLSID_StandardFacetMeshAccumulator, NULL, CLSCTX_INPROC_SERVER, IID_IShFacetMeshAccumulator, (LPVOID*)&accu);
- EnumFacets(AccuFacet, accu, 0);
- accu->MakeFacetMesh(amesh);
- accu->Release();
- return S_OK;
- }
-
- HRESULT Flat::MakeFacetMesh(NUM3D lod, FacetMesh &amesh) {
- return MakeFacetMesh((short)0, amesh);
- }
-
- // Give the boundary Box
- HRESULT Flat::GetBBox(THIS_ BOX3D* bbox) {
- bbox->fMin[0]=-10.0;
- bbox->fMax[0]=10.0;
- bbox->fMin[1]=-10.0;
- bbox->fMax[1]=10.0;
- bbox->fMin[2]=0.0;
- bbox->fMax[2]=0.0;
- return NOERROR;
- }
-
- // -- Shading calls
- ULONG Flat::GetUVSpaceCount(THIS) {
- return 1; // the star is describe with only 1 UV-Space
- }
-
- HRESULT Flat::GetUVSpace(THIS_ ULONG uvSpaceID, UVSpaceInfo* uvSpaceInfo) {
- NUM3D size;
- if (uvSpaceID == 0) {
- size = 10.0;
- uvSpaceInfo->fMin[0] = 0.0; // u coordinate goes from 0 to 10*2
- uvSpaceInfo->fMax[0] = size*2.0;
- uvSpaceInfo->fMin[1] = 0.0; // v coordinate goes from 0 to 10*2
- uvSpaceInfo->fMax[1] = size*2.0;
- uvSpaceInfo->fWraparound[0] = FALSE; // No Wrap around
- uvSpaceInfo->fWraparound[1] = FALSE;
- /*uvSpaceInfo->fIsFlatSurface = TRUE; // the surface is flat
- // Flat transformation
- // - Point to UV
- // -- Offset to have (0,0) in the corner of the surface
- uvSpaceInfo->fUVOffset[0]=size;
- uvSpaceInfo->fUVOffset[1]=size;
- // -- u projector
- uvSpaceInfo->fProjU[0]=1.0;
- uvSpaceInfo->fProjU[1]=0.0;
- uvSpaceInfo->fProjU[2]=0.0;
- // -- v projector
- uvSpaceInfo->fProjV[0]=0.0;
- uvSpaceInfo->fProjV[1]=1.0;
- uvSpaceInfo->fProjV[2]=0.0;
- // - UV to Point
- // -- No Offset
- uvSpaceInfo->fOffset[0]=-size;
- uvSpaceInfo->fOffset[1]=-size;
- // -- x projector
- uvSpaceInfo->fProjX[0]=1.0;
- uvSpaceInfo->fProjX[1]=0.0;
- // -- y projector
- uvSpaceInfo->fProjY[0]=0.0;
- uvSpaceInfo->fProjY[1]=1.0;
- // -- z projector
- uvSpaceInfo->fProjZ[0]=0.0;
- uvSpaceInfo->fProjZ[1]=0.0;*/
-
- }
- return NOERROR;
- }
-
- // We use the default interpolation method to get all the coordinate of a point in UV Coordinates
- HRESULT Flat::UV2XYZ(THIS_ VECTOR2D* uv, ULONG uvSpaceID, VECTOR3D* resultPosition, BOOLEAN* inUVSpace) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- // -- Ray Tracing calls
- HRESULT Flat::RayHit(THIS_ BOOLEAN* didHit, Ray3D* aR, RayHitParameters* RayHitParams, RayHit3D* hit) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Flat::GetRayHitDetails(THIS_ RayHit3D* hit) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Flat::RayAllHits(THIS_ Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, RayHitCallback callback, void* privData) {
- return ResultFromScode(E_NOTIMPL);
- }
-
-
-
-
-